<?php
namespace app\admin\controller;

// 公共类
use plug\SUtil;
use think\Controller;
use think\Db;

class Base extends Controller
{
    public $_userid;
    public $_user_name;
    public $_groupid;
    public $_adminArr;
    public $_licenseid;
    public $_shopid;
    public $limit = 10;

    public function __construct()
    {
        parent::__construct();
        header("Content-type:text/html;charset=utf-8");
        $this->loadLoginUser();
        $this->assign("thisadmin",$this->_user_name);
    }

    // 验证是否登录
    function isLogin()
    {
        if (!$this->_userid || !$this->_user_name) {
            $this->redirect('/login');
        }
        return true;
    }

    // 定义常量赋值登录的账号信息
    function loadLoginUser()
    {
        // 获取cookie
        $cookie = cookie('name');
        if ($cookie) {
            $adminModel = new \app\common\model\Admin();
            $adminArr = $adminModel->getOne(array("user_id" => $cookie['admin_userid']));
            if($adminArr){
                $group = Db::table('ddt_group')->where('group_id', $adminArr['group_id'])->field('license_data')->find();
                $this->_licenseid = $group;
                $this->_user_name = $adminArr['user_name'];
                $this->_userid = $adminArr['user_id'];
                $this->_groupid = $adminArr['group_id'];
                $this->_adminArr = $adminArr;
                $this->_shopid = $adminArr['shop_id'];
            }
        }
    }
}
